// home页面
import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    Platform,
    BackAndroid,
    StatusBar,
    TouchableOpacity,
    LayoutAnimation,
    Navigator,
    ListView
} from 'react-native';

//import Lock from './Lock';
import Home from './Home';

export default class App extends Component {
    constructor(props){
        super(props);
        this.state = {

        }
    }

    // 物理返回按钮的注册事件最好只在根组件注册一次
    componentWillMount() {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }
    componentWillUnmount() {
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    onBackAndroid = () => {
        const nav = this.refs.Navigator11;
        const routers = nav.getCurrentRoutes();
        if (routers.length > 1) {
            nav.pop();
            return true;
        }
        return false;
    };



    // Navigator组件在一个应用中只能呢用一次，每次新的组件都是往里面替换旧的组件
    // 在它里面要实现三个基本属性initialRoute：初始化数据。 configureScene：配置切换过场动画。 renderScene：定义要渲染的组件

    render() {
        return (
            <View style={styles.container}>
                <StatusBar
                    hidden={true}
                    animated={true}
                    backgroundColor="#00bfff"
                />
                <Navigator
                    ref="Navigator11"
                    initialRoute={{params:{name:'首页',age:12},component:Home}}
                    // 配置手势动画
                    configureScene={(route) => {
                        //if (route.sceneConfig) {
                        //
                        //    let res=route.sceneConfig;
                        //    res.gestures=null;
                        //    return res;
                        //    return route.sceneConfig;
                        //}
                        return Navigator.SceneConfigs.PushFromRight;
                    }}

                    // 渲染初始的页面
                    renderScene={(route, navigator) =>{
                        let DefaultComponent=route.component;
                        return <DefaultComponent {...route.params}  navigator={navigator}/>
                    }
                  }
                />
            </View>


        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1
    }
});
